02aa172916ca81a22c899239f5533f6ed99d6084,src/edu/stanford/nlp/classify/demo/ClassifierDemo.java,ClassifierDemo,main,#String[]#,18
Before Change
class ClassifierDemo {
public static void main(String[] args) throws Exception {
ColumnDataClassifier cdc = new ColumnDataClassifier("examples/cheese2007.prop");
Classifier<String,String> cl =
cdc.makeClassifier(cdc.readTrainingExamples("examples/cheeseDisease.train"));
for (String line : ObjectBank.getLineIterator("examples/cheeseDisease.test", "utf-8")) {
// instead of the method in the line below, if you have the individual elements
// already you can use cdc.makeDatumFromStrings(String[])
Datum<String,String> d = cdc.makeDatumFromLine(line);
System.out.println(line + " ==> " + cl.classOf(d));
}
demonstrateSerialization();
After Change
private static String where = "";
public static void main(String[] args) throws Exception {
if (args.length > 0) {
where = args[0] + File.separator;
}
System.out.println("Training ColumnDataClassifier");
ColumnDataClassifier cdc = new ColumnDataClassifier(where + "examples/cheese2007.prop");
cdc.trainClassifier(where + "examples/cheeseDisease.train");
System.out.println();
System.out.println("Testing predictions of ColumnDataClassifier");
for (String line : ObjectBank.getLineIterator(where + "examples/cheeseDisease.test", "utf-8")) {
// instead of the method in the line below, if you have the individual elements
// already you can use cdc.makeDatumFromStrings(String[])
Datum<String,String> d = cdc.makeDatumFromLine(line);
System.out.printf("%s ==> %s (%.4f)%n", line, cdc.classOf(d), cdc.scoresOf(d).getCount(cdc.classOf(d)));
}
System.out.println();
System.out.println("Testing accuracy of ColumnDataClassifier");
Pair<Double, Double> performance = cdc.testClassifier(where + "examples/cheeseDisease.test");
System.out.printf("Accuracy: %.3f; macro-F1: %.3f%n", performance.first(), performance.second());
demonstrateSerialization();
demonstrateSerializationColumnDataClassifier();